package com.example.bookstore.api

import com.example.bookstore.dao.CarousalDao
import com.example.bookstore.entity.CarousalEntity
import com.example.bookstore.service.CarousalService
import com.example.bookstore.validate.PageNSizeValidate
import com.fasterxml.jackson.annotation.JsonView
import io.swagger.annotations.Api
import io.swagger.annotations.ApiOperation
import org.springframework.validation.annotation.Validated
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController

/**
 * Created by IntelliJ IDEA.
 * User: lvshe
 * Date: 2019/8/10
 * Time: 13:45
 */
@Api(tags = ["书籍"], basePath = "/api/carousal")
@RestController
@RequestMapping("/api/carousal")
class CarousalController : BaseController<CarousalService, CarousalDao, CarousalEntity>() {

    @ApiOperation("获取轮番图列表", notes = "获取轮番图列表，根据order从小到大排序返回")
    @GetMapping("/list")
    @JsonView(CarousalEntity.CarousalWithBookView::class)
    override fun getAllPageable(@Validated pageNSizeValidate: PageNSizeValidate): MutableList<CarousalEntity> {
        return super.getAllPageable(pageNSizeValidate).sortedBy { it.order }.toMutableList()
    }


}